<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="box"></div>

    <script>
      console.log(123);
      const str =
        'Theory offers an [up to 60% off+extra 25% off Clothing Sale] https://www.toryburch.com/en-us/sale/view-all/  dsadhjkwad fecsawx [ssxxwa] https://www.toryburch.com/en-us/sale/view-all2/';

      // 使用正则表达式来匹配类似的字符串
      const regex = /\[(.*?)\]\s(https:\/\/[^\s]+?)(?=\s|$)/g;
      const replacedStr = str.replace(regex, (match, group) => {
        const url = match.split(' ')[0]; // 获取URL
        const text = group; // 获取链接文本
        console.log(url, text);
        return `<a href="${url}">${text}</a>`;
      });
      box.innerHTML = replacedStr;
    </script>
  </body>
</html>
